/**
 * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
 * author: huaping.liao huaping.liao@rock-chips.com
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <stdio.h>
#include <stdlib.h>

void (*poweroff_call)(int cmd, void *msg0, void *msg1);

int poweroff_reg_callback(void (*call)(int cmd, void *msg0, void *msg1))
{
	poweroff_call = call;
	return 0;
}

int video_deinit()
{
	char parkingrec = 0;

#ifdef PROTOCOL_IOTC
	protocol_rk_iotc_destroy();
#endif
#ifdef PROTOCOL_GB28181
	protocol_rk_gb28181_destroy();
#endif
#ifdef MSG_FWK
	rk_fwk_controller_destroy();
	rk_fwk_glue_destroy();
#endif

	wifi_management_stop();
	if (poweroff_call)
		(*poweroff_call)(0, NULL, NULL);
	video_record_deinit();
	//videoplay_deinit();
	fs_manage_deinit();
    
	/* must after uevent deinit */
	video_record_destroy_lock();
	return 0;
}

int power_reboot(void)
{
	printf("reboot now\n");
	video_deinit();
	runapp("busybox reboot");
	exit(0);
}

int power_shutdown(void)
{
	printf("shutdown now\n");
	video_deinit();
	runapp("busybox poweroff");
	exit(0);
}
